package com.niit.serviceorder.controller;

import com.niit.servicecommon.entity.Order;
import com.niit.serviceorder.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrderController {
    
    @Autowired
    private OrderService orderService;

    @Value("${server.port}")
    private String port;

    /**
     * 查询所有订单
     */
    @GetMapping
    public List<Order> getAllOrders() {
        System.out.println("port:" + port);
        return orderService.getAllOrders();
    }
    
    /**
     * 根据ID查询订单
     */
    @GetMapping("/{id}")
    public Order getOrderById(@PathVariable Long id) {
        return orderService.getOrderById(id);
    }
    
    /**
     * 添加订单
     */
    @PostMapping
    public void addOrder(@RequestBody Order order) {
        orderService.addOrder(order);
    }
    
    /**
     * 更新订单
     */
    @PutMapping
    public void updateOrder(@RequestBody Order order) {
        orderService.updateOrder(order);
    }
    
    /**
     * 删除订单
     */
    @DeleteMapping("/{id}")
    public void deleteOrder(@PathVariable Long id) {
        orderService.deleteOrder(id);
    }
}